package com.bjsxt.reflex;

import javax.print.attribute.standard.Media;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;

public class ReflectDemo {
    public void method1(){
        System.out.println("Method1......");
    }
    public void method2(){
        System.out.println("Method2......");
    }
    public void method3(){
        System.out.println("Method3......");
    }
}

class Test{
    public static void main(String[] args) throws Exception {
        ReflectDemo rd = new ReflectDemo();
        if (args!=null&&args.length>0){
            //获取ReflectDemo的Class对象
            Class clazz = rd.getClass();
            //通过反射获取ReflectDemo下的所有方法
            Method[] ms = clazz.getMethods();
            for (String str:args){
                for (int i =0;i<ms.length;i++){
                    if (str.equalsIgnoreCase(ms[i].getName())){
                        ms[i].invoke(rd);
                        break;
                    }
                }
            }
        }else {
            rd.method1();
            rd.method2();
            rd.method3();
        }
    }
}